<template>
  <div class="app-container">
    <DashboardHeader />
    <div class="main-content">
      <div class="left-panel">
        <ControlPanel />
        <StatsPanel />
      </div>
      <div class="replica-groups-container">
        <ReplicaGroup 
          v-for="group in replicaGroups" 
          :key="group.id"
          :group="group"
          @deactivate-gpu="deactivateGPU"
          @reactivate-group="reactivateGroup"
        />
      </div>
      <br>
      <!-- <CommGraph /> -->
    </div>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useTrainingStore } from './stores/training'
import DashboardHeader from './components/DashboardHeader.vue'
import ControlPanel from './components/ControlPanel.vue'
import StatsPanel from './components/StatsPanel.vue'
import ReplicaGroup from './components/ReplicaGroup.vue'
import CommGraph from './components/CommGraph.vue'

const store = useTrainingStore()
store.initialize()

const replicaGroups = computed(() => Object.values(store.replicaGroups))

function deactivateGPU(gpuId) {
  store.deactivateGPU(gpuId)
}

function reactivateGroup(groupId) {
  store.reactivateGroup(groupId)
}
</script>

<style scoped>
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f5f7fa;
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.left-panel {
  width: 320px;
  background-color: white;
  border-right: 1px solid #e8e8e8;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.replica-groups-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  align-content: start;
}

@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
  }
  
  .left-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #e8e8e8;
  }
}
</style>